<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            background-color: rgb(red, green, blue);
        }
    </style>
</head>
<body>
    <button>点击</button>
    <div class = 'div'></div>
    <script>
        let btn = document.querySelector('button')
        let divEl = document.querySelector('.div')
        let flag
        btn.onclick  = function() {
            flag = !flag
            divEl.innerHTML = 
            `
            <div style = "color:${flag?'red':'blue'}">
                我是div
            </div>
            <div style = "background-color: ${randomColor()}">
                随机背景色
            </div>
            `
        }
        function randomColor() {
            let a = parseInt(Math.random()* 256)
            let b = parseInt(Math.random()* 256)
            let c = parseInt(Math.random()* 256)
            // console.log(`rgb = (${a}, ${b}, ${c})`)

            return `rgb(${a},${b},${c})`
        }

    </script>
</body>
</html>